mod modal;
mod util;
mod sys_controller;
mod auths;

use axum::response::Html;
use axum::routing::get;
use axum::Router;
use tower_http::cors::CorsLayer;
use void_log::*;
use crate::util::Config;

async fn server(config: Config) {
    let address = format!("0.0.0.0:{}", config.server_port.unwrap_or(8080));
    log_info!("Server启动参数: {address}");
    let mut app = Router::new()
        .route("/", get(|| async { Html("数据中心接口") }));
    app = sys_controller::user_router(app).await;
    app = app.layer(CorsLayer::permissive());
    let listener = tokio::net::TcpListener::bind(address).await.unwrap();
    axum::serve(listener, app).await.unwrap();
}

#[tokio::main]
async fn main() {
    let config = Config::get().await;
    if config.sys_token == Some("qwe_rty_uio".to_string()) {
        log_info!("激活成功");
        server(config).await;
    } else {
        log_warn!("激活码错误")
    }
}